package com.control.qct.businesssteward.activity;

import android.os.Bundle;
import android.view.View;

import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.base.BaseActivity;
import com.control.qct.businesssteward.base.BaseBean;
import com.control.qct.businesssteward.fragment.PaymentFragment;
import com.control.qct.businesssteward.fragment.PaymentStyleFragment;
import com.control.qct.businesssteward.httputils.HttpUtils;
import com.control.qct.businesssteward.model.DoPayGoodsModel;
import com.control.qct.businesssteward.model.DoPayPromotionGoodsModel;
import com.control.qct.businesssteward.model.OpenOrderModel;
import com.control.qct.businesssteward.utils.GsonUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 结算
 * Created by Administrator on 2017/12/1 0001.
 */

public class PaymentActivity extends BaseActivity {
    private BaseBean mBaseBean;
    private String mData;
    public List<DoPayPromotionGoodsModel> mDoPayPromotionGoodsModelList;
    public DoPayGoodsModel mDoPayGoodsModel;
    public OpenOrderModel.CarItemsBean.TotalBean mTotalBean;
    private int id;

    public PaymentActivity() {
        super(R.layout.activity_payment);
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        super.getBundleExtras(extras);
        mBaseBean = (BaseBean) extras.getSerializable("data");
        mTotalBean = (OpenOrderModel.CarItemsBean.TotalBean) extras.getSerializable("total");
        id = extras.getInt("id");
        if (id == 1){
            mDoPayGoodsModel = (DoPayGoodsModel) extras.getSerializable("order_information");
        }
    }

    @Override
    protected void initView() {
        setLeftIcon(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        setTitle("结算");
        if (id == 1){
            replaceFragment(R.id.fl_content, new PaymentStyleFragment());
            return;
        }
        mData = GsonUtil.GsonString(mBaseBean.getData());
        if (mBaseBean.getMessage().contains("选择促销")) {
            mDoPayPromotionGoodsModelList = GsonUtil.jsonToList(mData, DoPayPromotionGoodsModel.class);
            replaceFragment(R.id.fl_content, new PaymentFragment());
        } else {
            mDoPayGoodsModel = GsonUtil.GsonToBean(mData, DoPayGoodsModel.class);
            replaceFragment(R.id.fl_content, new PaymentStyleFragment());
        }
    }

    private Map<String, String> mParams;

    /**
     * 结算新增订单
     */
    public void gotoNewPayGoods(String promotionJson) {
        mParams = new HashMap<>();
        mParams.put("marketingResultModels", promotionJson);
        mNetProtocol.gotoNewPayGoods(this, mParams, new HttpUtils.IHttpResult() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                mDoPayGoodsModel = (DoPayGoodsModel) baseBean.getData();
                replaceFragment(R.id.fl_content, new PaymentStyleFragment());
            }

            @Override
            public void onFail(BaseBean baseBean) {

            }
        });
    }
}
